<!DOCTYPE html>
<html>
<head>
    <title>历史</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <#--样式-->
    <link rel="stylesheet" media="screen" href="${request.contextPath}/css/style.css">
    <#--layui-->
    <link rel="stylesheet" media="screen" href="${request.contextPath}/layui/css/layui.css">

</head>
<body >





    <div class="content" >



       <div >
           <#--月亮放置区-->
           <div class="light" style="cursor:pointer;" onclick="window.location.href = '/history/'">
           </div>

           <hr class="line-left">
           <hr class="line-right">

           <div class="main">
               <h1 class="title">地点列表</h1>
           </div>




           <div class="textContent" style="padding-bottom: 300px;">

               <div style="width: 900px;">
                   <div class="layui-form-item">
                       <label class="layui-form-label">地名</label>
                       <div class="layui-input-block" style="width: 300px;display: inline-block;">
                           <input type="text" value="${place!''}" name="place" required  lay-verify="required" placeholder="请输入要搜索的地名" autocomplete="off" class="layui-input">
                       </div>
                       <button class="layui-btn" type="button" onclick="selectPlace()">搜索</button>

                   </div>
                   <br/>
                   <br/>

                   <table class="layui-table" lay-size="sm">
                       <tr>
                           <td style="width: 160px">开始时间</td>
                           <td style="width: 160px">结束时间</td>
                           <td style="width: 140px">古地名</td>
                           <td style="width: 150px">现地名</td>
                           <td style="width: 170px;">备注</td>
                           <td style="width: 120px">操作</td>
                       </tr>
                       <#if landPage??>
                           <#if landPage.records??>
                               <#list landPage.records as land>
                                   <tr>
                                       <td>
                                           ${land.startYear}<#if land.startYear??>年</#if>
                                           ${land.startMonth}<#if land.startMonth??>月</#if>
                                           ${land.startDay}<#if land.startDay??>日</#if>
                                       </td>
                                       <td>
                                           ${land.endYear}<#if land.endYear??>年</#if>
                                           ${land.endMonth}<#if land.endMonth??>月</#if>
                                           ${land.endDay}<#if land.endDay??>日</#if>
                                       </td>
                                       <td>${land.name}</td>
                                       <td>${land.nowName}</td>
                                       <td>${land.bz}</td>
                                       <td>
                                           <button class="layui-btn layui-btn-xs" type="button" onclick="toUpdLand('${land.id!''}')">修改</button>
                                           <button class="layui-btn layui-btn-danger layui-btn-xs" type="button" onclick="delLand('${land.id!''}')">删除</button>
                                       </td>
                                   </tr>
                               </#list>
                           </#if>

                       <#else >
                            <tr>
                                <td colspan="6">暂无数据</td>
                            </tr>
                       </#if>
                   </table>

                   <div id="page"></div>

               </div>




           </div>



       </div>
    </div>




</body>


<!-- scripts -->

<#--layui-->
<script src="${request.contextPath}/layui/layui.js"></script>
<#--js-->
<script src="${request.contextPath}/js/jquery.min.js"></script>


<script>


    layui.use('laypage', function(){
        var laypage = layui.laypage;

        //执行一个laypage实例
        laypage.render({
            elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
            ,limit: ${landPage.size!0}
            ,limits: [10, 20, 30, 40, 50] //每页条数的选择项。如果 layout 参数开启了 limit，则会出现每页条数的select选择框
            // ,theme: '#ff0000'
            ,count: ${landPage.total!0} //数据总数，从服务端得到
            ,curr: ${landPage.current!0} //当前页，如果是ajax类型的，这个参数可以不需要
            ,jump: function(obj, first){ //点击上一页或者下一页触发函数
                console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                console.log(obj.limit); //得到每页显示的条数

                //首次不执行
                if(!first){
                    var place = $("input[name='place']").val();
                    if (place == null || place === ""){
                        window.location.href = "/history/other/toLandList?size=" + obj.limit + "&current=" + obj.curr;

                    } else {
                        window.location.href = "/history/other/toLandList?size=" + obj.limit + "&current=" + obj.curr + "&place=" + place;
                    }
                }
            }
        });
    });


    // 引入弹出层
    var form = null;
    layui.use('form', function(){
        form = layui.form;
    });

    /**
     * 根据地名搜索
     */
    function selectPlace() {
        var place = $("input[name='place']").val();
        if (place == null || place === ""){
            layer.msg("请输入地名");
            return;
        }
        window.location.href = "/history/other/toLandList?place=" + place;
    }

    /**
     * 根据主键删除 地点
     * @param id
     */
    function delLand(id) {
        if (id == null || id === ""){
            layer.msg("数据异常");
            return;
        }
        layer.confirm('确认是否删除地点，注意：删除后不可恢复?', {icon: 3, title:'警告'}, function(index){
            $.ajax({
                url:'/history/other/delLand', //请求的url地址
                dataType:'json', //返回的格式
                data: {"id" : id},//参数值 {"id":"value"}
                type:'get', //请求的方式
                beforeSend:function(){ //请求前的处理
                    console.log("提交的数据:" + id)
                },
                success:function (req) {
                    if (req != null){
                        if (req.status === "success"){
                            layer.msg(req.msg);
                            window.location.reload();

                        } else {
                            layer.msg(req.msg);
                        }
                    } else {
                        console.log(req);
                    }
                },
                error:function (e) {
                    console.log(e);
                    layer.msg("未知错误");
                }

            });

            layer.close(index);
        });
    }

    /**
     * 跳转到 地点更新页面
     * @param id 主键
     */
    function toUpdLand(id) {
        if (id == null || id === ""){
            layer.msg("数据异常");
            return;
        }
        window.location.href = "/history/other/toUpdLand?id=" + id;
    }

</script>



</html>